import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import dynamicImportVars from "@rollup/plugin-dynamic-import-vars"
import { createSvg } from "./src/icons/index";
export default defineConfig({
  plugins: [vue(),createSvg('./src/icons/svg/')],
  base: "./",
  resolve: {
    alias: {
      "@": "/src",
      "@assets": '/src/assets',
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve(
            "src/styles/main.less"
          )}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
  build: {
    outDir: "dist",
    assetsDir: "assets",
    sourcemap: true,
    minify: "terser",
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      plugins: [
        dynamicImportVars()
      ],
      output: {
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
        chunkFileNames: "js/[name].[hash].js",
      },
    },
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
      output: {
        comments: true,
      },
    },
  },
  server: {
    https: false,
    open: true,
    cors: true,
    port: 8080,
    host: "0.0.0.0",
    proxy: {
      "/api": {
        target: 'http://ci5qwy.natappfree.cc/review-manager',
        changeOrigin: true,
        secure: false,
        ws: false,
        rewrite: (path) => path.replace(/^\/api/, "")
      },
    },
  },
  optimizeDeps: {
    include: [],
  },
});
